
using System;
using UnityEngine;
using UnityEngine.UI;
using Utils;

public class PausePanel : MonoBehaviour
{
    private Button continueBtn, settingBtn, saveBtn;

    private void Awake()
    {
        continueBtn = UITool.GetComponent<Button>("Btns/ContinueBtn", gameObject);
        settingBtn = UITool.GetComponent<Button>("Btns/SettingBtn", gameObject);
        saveBtn = UITool.GetComponent<Button>("Btns/SaveBtn", gameObject);
        AddButtonClickEvent();

    }

    void OnEnable()
    {
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape)) Destroy();
    }

    private void OnDestroy()
    {
        continueBtn.onClick.RemoveListener(OnClickContinueBtn);
        settingBtn.onClick.RemoveListener(OnClickSettingBtn);
        saveBtn.onClick.RemoveListener(OnClickSaveBtn);
    }

    private void AddButtonClickEvent()
    {
        continueBtn.onClick.AddListener(OnClickContinueBtn);
        settingBtn.onClick.AddListener(OnClickSettingBtn);
        saveBtn.onClick.AddListener(OnClickSaveBtn); 
    }

    private void OnClickContinueBtn()
    {
        GameController.Instance().FSM.CurGameState = GameState.Gaming;
        Destroy();
    }

    private void OnClickSettingBtn()
    {
        GameController.Instance().panelCtr.LoadSettingPanel();
    }
    
    private void OnClickSaveBtn()
    {
        // GameController.Instance().FSM.CurGameState = GameState.Login;
        // GameController.Instance().archiveCtr.SaveArchive();
        GameController.Instance().Exit();
    }

    private void Destroy()
    {
        Time.timeScale = 1;
        Destroy(gameObject);
    }
}